package JavaSE.ThreadLearning.RunnableLearning.Demo02;

/**
 *  学习 利用匿名内部类声明创建多线程
 */
public class AnonymousInnerClass {
    public static void main(String[] args) {
        // 1.继承Thread父类
        // new MyThread().start();
        new Thread("辉夜"){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"--->"+i);
                }
            }
        }.start();

        // 2.线程接口Runnable
        // 利用多态：Runnable r = new RunnableImpl();
        Runnable r = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"--->"+i);
                }
            }
        };
        new Thread(r,"白银").start();

        // 3.简化接口的方式（严重套娃）
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"--->"+i);
                }
            }
        },"藤原").start();
    }
}
